/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MainWindow.java
 *
 * Created on Aug 4, 2011, 12:38:21 PM
 */
package dcds2;

import java.text.DateFormat;
import java.text.*;
import java.util.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;
import javax.swing.*;
import java.sql.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.Timer;

/**
 *
 * @author Mesan
 */
public class MainWindow extends javax.swing.JFrame {

    String selectPatient = "";
    String selectProcedure = "";
    List patientList;
    List procedureList;
    public int b=0;
    int cnt;
    double pprice, Total;
    
    private DefaultTableModel modelPatient, modelProcedure, modelTransaction, modelReport;
   
    /** Creates new form MainWindow */
    public MainWindow(int a) { // WHERE A is the index of the tab
       b=a;
        
        
        modelPatient = new DefaultTableModel(new Object[][]{}, new String[] {"ID","Last Name", "First Name", "Middle Name", "Birthdate"});
        modelProcedure = new DefaultTableModel(new Object[][]{}, new String[]{"ID","Procedure Name", "Price"});
        modelTransaction = new DefaultTableModel(new Object[][]{}, new String[]{"Trans No","Date","ID","Patient Name"});
        modelReport = new DefaultTableModel(new Object[][]{}, new String[]{"Date", "Procedure Count", "Profit"});
        
        initComponents();
        tblPatient.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        tblProcedure.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        tblTransaction.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        tblTransaction.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        tabbedPanel.setSelectedIndex(a);

        setLocationRelativeTo(null);
        tblPatient.setAutoCreateRowSorter(true);
        b = tabbedPanel.getSelectedIndex();
        Timer timer = new Timer(1000, new MyClockActionListener());
        timer.start();
  
        try{
            ConnectionFactory myFactory = ConnectionFactory.getFactory();
            Connection conn = myFactory.getConnection();
            
            int i = 0;
            
            PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM dcds.procedures");

            ResultSet rs = pstmt.executeQuery();
            
            while(rs.next())
           { 

           String name = rs.getString("procedureName");
           double price = rs.getDouble("procedurePrice");
           int id = rs.getInt("procedureID");
           
           modelProcedure.addRow(new Object[] {"", ""});
           tblProcedure.setValueAt(id, i, 0);
           tblProcedure.setValueAt(name, i,1);
           tblProcedure.setValueAt("Php "+ price, i, 2);
           
           i++;
            }
               
        conn.close();
    }catch(Exception e){
        e.printStackTrace();
    }
        
        //For the Patient
    try{
        ConnectionFactory myFactory = ConnectionFactory.getFactory();
        Connection conn = myFactory.getConnection();
            
        int i = 0;
            
        PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM dcds.patient");
        
        ResultSet rs = pstmt.executeQuery();
        
        while(rs.next()){
        
            String month = rs.getString("pBirthMonth");
            String day = rs.getString("pBirthDay");
            String year = rs.getString("pBirthYear");
            String fName = rs.getString("pFirstName");
            String mName = rs.getString("pMiddleName");
            String lName = rs.getString("pLastName");
            int id = rs.getInt("patientID");
            String date = month+ " " + day +", "+year;
            
            modelPatient.addRow(new Object[] {"","", "", "", ""});
            tblPatient.setValueAt(date, i, 4);
            tblPatient.setValueAt(fName, i, 2);
            tblPatient.setValueAt(mName, i, 3);
            tblPatient.setValueAt(lName, i, 1);
            tblPatient.setValueAt(id, i, 0);
            
            i++;
        }
        conn.close();
    }catch(Exception e){
        e.printStackTrace();
    }
    
    //For the Transactions
    try{
        ConnectionFactory myFactory = ConnectionFactory.getFactory();
        Connection conn = myFactory.getConnection();
            
        int i = 0;
            
        PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM dcds.transactions");
        
        ResultSet rs = pstmt.executeQuery();
        
        while(rs.next()){
        
            int transactionID = rs.getInt("transactionID");
            int patientID = rs.getInt("patientID");
            String pName = rs.getString("pName");
            String transactionDate = rs.getString("transactionDate");
            
            modelTransaction.addRow(new Object[] {"","","",""});
            tblTransaction.setValueAt(transactionID, i, 0);
            tblTransaction.setValueAt(transactionDate, i, 1);
            tblTransaction.setValueAt(patientID, i, 2);
            tblTransaction.setValueAt(pName, i, 3);
            
            i++;
        }
        System.out.println(modelPatient.getRowCount());
        conn.close();
    }catch(Exception e){
        e.printStackTrace();
    }
        
    //For the Reports
    
    try{
        ConnectionFactory myFactory = ConnectionFactory.getFactory();
        Connection conn = myFactory.getConnection();
            
        int i = 0;
        
        //gets all dates and makes it into a string
        PreparedStatement pstmt0 = conn.prepareStatement("SELECT transactionDate FROM transactions GROUP BY transactionDate ORDER BY transactionDate");
        ResultSet rs0 = pstmt0.executeQuery();
        rs0.last();
        int numRows = rs0.getRow();
        String[] Dates = new String[rs0.getRow()];
        rs0.beforeFirst();
        int index = 0;
        while(rs0.next()){
            Dates[index] = rs0.getString("transactionDate");
            index++;
        }
        String dateString = "";
        for(index = 0; index < numRows-1; index++){
            dateString += "SELECT SUM(procedurePrice) AS ProcSum, COUNT(*) AS ProcNum, dcds.transactions.transactionDate FROM dcds.transprocdetails, dcds.transactions where dcds.transactions.transactiondate = '"+Dates[index]+"' AND dcds.transactions.transactionID = dcds.transprocdetails.transactionID UNION ";
        }
        dateString += "SELECT SUM(procedurePrice) AS ProcSum, COUNT(*) AS ProcNum, dcds.transactions.transactionDate FROM dcds.transprocdetails, dcds.transactions where dcds.transactions.transactiondate = '"+Dates[index]+"' AND dcds.transactions.transactionID = dcds.transprocdetails.transactionID";
        
        PreparedStatement pstmt = conn.prepareStatement(dateString);
        
        ResultSet rs = pstmt.executeQuery();
        
        Total = 0;
                
        while(rs.next()){
            String date = rs.getString("transactionDate");
            
            modelReport.addRow(new Object[] {"", "", ""});
            tblReport.setValueAt(date, i, 0);
            
            cnt = rs.getInt("procNum");
            pprice = rs.getDouble("procSum");
            
            tblReport.setValueAt(cnt, i , 1);
            tblReport.setValueAt("Php " + pprice, i, 2);
           
            Total += pprice;
            
            String properTotal = ("Php " + Total);
            
            jTextField3.setText(properTotal);
            
            i++;
            }
        
        conn.close();
        }catch(Exception e){
        e.printStackTrace();
            }    
    }
    
    public MainWindow(String selectPatient1, String selectProcedure1, List patientList1, List procedureList1){
       
        selectPatient = selectPatient1;
        selectProcedure = selectProcedure1;
        patientList = patientList1;
        procedureList = procedureList1;
        
        
    }
 
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        tabbedPanel = new javax.swing.JTabbedPane();
        panelHome = new javax.swing.JPanel();
        labelDate = new javax.swing.JLabel();
        labelGreeting1 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        panelPatient = new javax.swing.JPanel();
        btnAddPatient = new javax.swing.JButton();
        btnViewPatient = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblPatient = new javax.swing.JTable();
        txtSearchPatient = new javax.swing.JTextField();
        btnSearchPatient = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        panelProcedure = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tblProcedure = new javax.swing.JTable();
        btnAddProcedure = new javax.swing.JButton();
        btnViewProcedure = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JSeparator();
        btnSearchProcedure = new javax.swing.JButton();
        txtSearchProcedure = new javax.swing.JTextField();
        panelTransaction = new javax.swing.JPanel();
        txtSearchPatientTransaction = new javax.swing.JTextField();
        btnSearchTransaction = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        tblTransaction = new javax.swing.JTable();
        jSeparator3 = new javax.swing.JSeparator();
        btnEditTransaction = new javax.swing.JButton();
        btnAddTransaction = new javax.swing.JButton();
        panelReport = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        tblReport = new javax.swing.JTable();
        jSeparator4 = new javax.swing.JSeparator();
        jLabel2 = new javax.swing.JLabel();
        jCalendarCombo1 = new org.gui.JCalendarCombo();
        jLabel3 = new javax.swing.JLabel();
        jCalendarCombo2 = new org.gui.JCalendarCombo();
        btnFilter = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        jTextField3 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("DENTAL CLINIC DATABASE SYSTEM");
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setName("mainFrame"); // NOI18N
        setResizable(false);

        jPanel1.setBackground(new java.awt.Color(0, 61, 0));
        jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        tabbedPanel.setBackground(new java.awt.Color(204, 204, 204));
        tabbedPanel.setTabLayoutPolicy(javax.swing.JTabbedPane.SCROLL_TAB_LAYOUT);
        tabbedPanel.setTabPlacement(javax.swing.JTabbedPane.LEFT);
        tabbedPanel.setToolTipText("");
        tabbedPanel.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        tabbedPanel.setName(""); // NOI18N

        labelDate.setFont(new java.awt.Font("Times New Roman", 1, 14));
        labelDate.setDebugGraphicsOptions(javax.swing.DebugGraphics.BUFFERED_OPTION);

        labelGreeting1.setFont(new java.awt.Font("Times New Roman", 1, 18));
        labelGreeting1.setText("Good day!");

        jLabel5.setFont(new java.awt.Font("Verdana", 0, 12));
        jLabel5.setText("This is a database system project developed by CS students from DLSU-M.");

        jLabel6.setFont(new java.awt.Font("Verdana", 0, 12));
        jLabel6.setText("For technical help, please e-mail any of the following:");

        jLabel7.setFont(new java.awt.Font("Verdana", 0, 12));
        jLabel7.setText("mesanchavez@gmail.com");

        jLabel8.setFont(new java.awt.Font("Verdana", 0, 12));
        jLabel8.setText("deluna.lin@gmail.com");

        jLabel9.setFont(new java.awt.Font("Verdana", 0, 12));
        jLabel9.setText("patrick.detera@gmail.com");

        jLabel10.setFont(new java.awt.Font("Verdana", 0, 12));
        jLabel10.setText("jellene_martinez@dlsu.ph");

        javax.swing.GroupLayout panelHomeLayout = new javax.swing.GroupLayout(panelHome);
        panelHome.setLayout(panelHomeLayout);
        panelHomeLayout.setHorizontalGroup(
            panelHomeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelHomeLayout.createSequentialGroup()
                .addGroup(panelHomeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelHomeLayout.createSequentialGroup()
                        .addGap(40, 40, 40)
                        .addGroup(panelHomeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6)
                            .addComponent(jLabel5)
                            .addComponent(labelDate, javax.swing.GroupLayout.PREFERRED_SIZE, 418, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(labelGreeting1, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(panelHomeLayout.createSequentialGroup()
                        .addGap(63, 63, 63)
                        .addGroup(panelHomeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel8)
                            .addComponent(jLabel7)
                            .addGroup(panelHomeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel10)
                                .addComponent(jLabel9)))))
                .addContainerGap(172, Short.MAX_VALUE))
        );
        panelHomeLayout.setVerticalGroup(
            panelHomeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelHomeLayout.createSequentialGroup()
                .addGap(40, 40, 40)
                .addComponent(labelGreeting1, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(labelDate, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(26, 26, 26)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel9)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel10)
                .addContainerGap(66, Short.MAX_VALUE))
        );

        //labelDate.setText(now("MMMM dd, yyyy EEEE hh:mm:ss a"));

        tabbedPanel.addTab("", new javax.swing.ImageIcon(getClass().getResource("/images/module/ModuleHome.png")), panelHome); // NOI18N
        Date now = new Date();

        panelPatient.setMaximumSize(new java.awt.Dimension(500, 500));

        btnAddPatient.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/module/PatientAdd.png"))); // NOI18N
        btnAddPatient.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddPatientActionPerformed(evt);
            }
        });

        btnViewPatient.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/module/PatientView.png"))); // NOI18N
        btnViewPatient.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnViewPatientActionPerformed(evt);
            }
        });

        tblPatient.setModel(modelPatient);
        jScrollPane1.setViewportView(tblPatient);

        txtSearchPatient.setForeground(new java.awt.Color(102, 102, 102));
        txtSearchPatient.setText("Enter name here...");
        txtSearchPatient.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
        txtSearchPatient.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                txtSearchPatientMouseClicked(evt);
            }
        });
        txtSearchPatient.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtSearchPatientActionPerformed(evt);
            }
        });
        txtSearchPatient.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtSearchPatientFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtSearchPatientFocusLost(evt);
            }
        });
        txtSearchPatient.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtSearchPatientKeyTyped(evt);
            }
        });

        btnSearchPatient.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/module/ButtonSearch_1.png"))); // NOI18N
        btnSearchPatient.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSearchPatientActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelPatientLayout = new javax.swing.GroupLayout(panelPatient);
        panelPatient.setLayout(panelPatientLayout);
        panelPatientLayout.setHorizontalGroup(
            panelPatientLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelPatientLayout.createSequentialGroup()
                .addGroup(panelPatientLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelPatientLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(panelPatientLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btnSearchPatient, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtSearchPatient, javax.swing.GroupLayout.DEFAULT_SIZE, 191, Short.MAX_VALUE)
                            .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 191, Short.MAX_VALUE)))
                    .addGroup(panelPatientLayout.createSequentialGroup()
                        .addGap(39, 39, 39)
                        .addGroup(panelPatientLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(btnViewPatient, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)
                            .addComponent(btnAddPatient, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 465, Short.MAX_VALUE)
                .addContainerGap())
        );
        panelPatientLayout.setVerticalGroup(
            panelPatientLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelPatientLayout.createSequentialGroup()
                .addContainerGap(34, Short.MAX_VALUE)
                .addComponent(txtSearchPatient, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnSearchPatient, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnAddPatient, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(30, 30, 30)
                .addComponent(btnViewPatient, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(64, 64, 64))
            .addGroup(panelPatientLayout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 270, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(23, Short.MAX_VALUE))
        );

        tabbedPanel.addTab("", new javax.swing.ImageIcon(getClass().getResource("/images/module/ModulePatient.png")), panelPatient); // NOI18N

        tblProcedure.setModel(modelProcedure);
        tblProcedure.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                tblProcedureFocusGained(evt);
            }
        });
        jScrollPane2.setViewportView(tblProcedure);

        btnAddProcedure.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/module/ProcedureAdd.png"))); // NOI18N
        btnAddProcedure.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddProcedureActionPerformed(evt);
            }
        });

        btnViewProcedure.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/module/ProcedureView.png"))); // NOI18N
        btnViewProcedure.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnViewProcedureActionPerformed(evt);
            }
        });

        btnSearchProcedure.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/module/ButtonSearch_1.png"))); // NOI18N
        btnSearchProcedure.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSearchProcedureActionPerformed(evt);
            }
        });

        txtSearchProcedure.setForeground(new java.awt.Color(102, 102, 102));
        txtSearchProcedure.setText("Enter procedure name here...");
        txtSearchProcedure.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                txtSearchProcedureMouseClicked(evt);
            }
        });
        txtSearchProcedure.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtSearchProcedureFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtSearchProcedureFocusLost(evt);
            }
        });
        txtSearchProcedure.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtSearchProcedureKeyTyped(evt);
            }
        });

        javax.swing.GroupLayout panelProcedureLayout = new javax.swing.GroupLayout(panelProcedure);
        panelProcedure.setLayout(panelProcedureLayout);
        panelProcedureLayout.setHorizontalGroup(
            panelProcedureLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelProcedureLayout.createSequentialGroup()
                .addGroup(panelProcedureLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelProcedureLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(panelProcedureLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jSeparator2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtSearchProcedure, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 190, Short.MAX_VALUE)
                            .addComponent(btnSearchProcedure, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(panelProcedureLayout.createSequentialGroup()
                        .addGap(42, 42, 42)
                        .addGroup(panelProcedureLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btnAddProcedure, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnViewProcedure, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 462, Short.MAX_VALUE)
                .addContainerGap())
        );
        panelProcedureLayout.setVerticalGroup(
            panelProcedureLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelProcedureLayout.createSequentialGroup()
                .addGroup(panelProcedureLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelProcedureLayout.createSequentialGroup()
                        .addGap(22, 22, 22)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 278, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(panelProcedureLayout.createSequentialGroup()
                        .addGap(43, 43, 43)
                        .addComponent(txtSearchProcedure, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(11, 11, 11)
                        .addComponent(btnSearchProcedure, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btnAddProcedure, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btnViewProcedure, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(20, Short.MAX_VALUE))
        );

        tabbedPanel.addTab("", new javax.swing.ImageIcon(getClass().getResource("/images/module/ModuleProcedure.png")), panelProcedure); // NOI18N

        txtSearchPatientTransaction.setForeground(new java.awt.Color(102, 102, 102));
        txtSearchPatientTransaction.setText("Enter patient's name here...");
        txtSearchPatientTransaction.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                txtSearchPatientTransactionMouseClicked(evt);
            }
        });
        txtSearchPatientTransaction.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtSearchPatientTransactionActionPerformed(evt);
            }
        });
        txtSearchPatientTransaction.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtSearchPatientTransactionFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtSearchPatientTransactionFocusLost(evt);
            }
        });
        txtSearchPatientTransaction.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtSearchPatientTransactionKeyTyped(evt);
            }
        });

        btnSearchTransaction.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/module/ButtonSearch_1.png"))); // NOI18N
        btnSearchTransaction.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSearchTransactionActionPerformed(evt);
            }
        });

        tblTransaction.setModel(modelTransaction);
        jScrollPane3.setViewportView(tblTransaction);

        btnEditTransaction.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/module/TransactionEdit.png"))); // NOI18N
        btnEditTransaction.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditTransactionActionPerformed(evt);
            }
        });

        btnAddTransaction.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/module/TransactionAdd.png"))); // NOI18N
        btnAddTransaction.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddTransactionActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelTransactionLayout = new javax.swing.GroupLayout(panelTransaction);
        panelTransaction.setLayout(panelTransactionLayout);
        panelTransactionLayout.setHorizontalGroup(
            panelTransactionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelTransactionLayout.createSequentialGroup()
                .addGroup(panelTransactionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelTransactionLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(panelTransactionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtSearchPatientTransaction, javax.swing.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE)
                            .addComponent(btnSearchTransaction, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jSeparator3, javax.swing.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE)))
                    .addGroup(panelTransactionLayout.createSequentialGroup()
                        .addGap(44, 44, 44)
                        .addGroup(panelTransactionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(btnAddTransaction, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)
                            .addComponent(btnEditTransaction, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        panelTransactionLayout.setVerticalGroup(
            panelTransactionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelTransactionLayout.createSequentialGroup()
                .addContainerGap(40, Short.MAX_VALUE)
                .addComponent(txtSearchPatientTransaction, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnSearchTransaction)
                .addGap(18, 18, 18)
                .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnAddTransaction, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btnEditTransaction)
                .addGap(62, 62, 62))
            .addGroup(panelTransactionLayout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 286, Short.MAX_VALUE)
                .addContainerGap())
        );

        tabbedPanel.addTab("", new javax.swing.ImageIcon(getClass().getResource("/images/module/ModuleTransaction.png")), panelTransaction); // NOI18N

        tblReport.setModel(modelReport);
        tblReport.getTableHeader().setReorderingAllowed(false);
        jScrollPane4.setViewportView(tblReport);

        jSeparator4.setToolTipText("");
        jSeparator4.setName(""); // NOI18N

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel2.setText("From");

        jCalendarCombo1.setFont(new java.awt.Font("Tahoma", 0, 12));

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel3.setText("to");

        jCalendarCombo2.setFont(new java.awt.Font("Tahoma", 0, 12));

        btnFilter.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/module/ButtonSearch_1.png"))); // NOI18N
        btnFilter.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnFilterActionPerformed(evt);
            }
        });

        jLabel4.setText("Total Profit");

        jTextField3.setEditable(false);
        jTextField3.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        javax.swing.GroupLayout panelReportLayout = new javax.swing.GroupLayout(panelReport);
        panelReport.setLayout(panelReportLayout);
        panelReportLayout.setHorizontalGroup(
            panelReportLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelReportLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelReportLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelReportLayout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(18, 18, 18)
                        .addComponent(jCalendarCombo1, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jCalendarCombo2, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(30, 30, 30)
                        .addComponent(btnFilter, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jSeparator4, javax.swing.GroupLayout.DEFAULT_SIZE, 662, Short.MAX_VALUE))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelReportLayout.createSequentialGroup()
                .addGroup(panelReportLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(panelReportLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 291, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(panelReportLayout.createSequentialGroup()
                        .addGap(39, 39, 39)
                        .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 604, Short.MAX_VALUE)))
                .addGap(39, 39, 39))
        );
        panelReportLayout.setVerticalGroup(
            panelReportLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelReportLayout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addGroup(panelReportLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jCalendarCombo2, javax.swing.GroupLayout.DEFAULT_SIZE, 26, Short.MAX_VALUE)
                    .addGroup(panelReportLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 26, Short.MAX_VALUE)
                        .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnFilter, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jCalendarCombo1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 26, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addComponent(jSeparator4, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(11, 11, 11)
                .addGroup(panelReportLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        tabbedPanel.addTab("", new javax.swing.ImageIcon(getClass().getResource("/images/module/ModuleReport.png")), panelReport); // NOI18N

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/module/DCDS.png"))); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tabbedPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 767, Short.MAX_VALUE)
                    .addComponent(jLabel1))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 84, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tabbedPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 325, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        tabbedPanel.getAccessibleContext().setAccessibleName("");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txtSearchPatientActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtSearchPatientActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtSearchPatientActionPerformed

    private void txtSearchPatientTransactionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtSearchPatientTransactionActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_txtSearchPatientTransactionActionPerformed

    private void btnViewPatientActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnViewPatientActionPerformed
       
        if(tblPatient.getSelectedRow() == -1) {
            JOptionPane.showMessageDialog(new JFrame(), "Please select a patient first", "Error!", JOptionPane.ERROR_MESSAGE);
        }
        else{
            dispose();
            new ViewPatientWindow(getSelectedPatientID()).setVisible(true);
        }
    }//GEN-LAST:event_btnViewPatientActionPerformed

    private void btnAddPatientActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddPatientActionPerformed
        dispose();
        new AddPatientWindow().setVisible(true);
    }//GEN-LAST:event_btnAddPatientActionPerformed

    private void btnAddProcedureActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddProcedureActionPerformed
       dispose();
        new AddProcedureWindow().setVisible(true);
        
    }//GEN-LAST:event_btnAddProcedureActionPerformed

    private void btnViewProcedureActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnViewProcedureActionPerformed
        
        if(tblProcedure.getSelectedRow() == -1) {
            JOptionPane.showMessageDialog(new JFrame(), "Please select a procedure first", "Error!", JOptionPane.ERROR_MESSAGE);
        }
        else{
            dispose();
            new EditProcedureWindow(tblProcedure.getSelectedRow(), getSelectedProcedureID()).setVisible(true);
        }
    }//GEN-LAST:event_btnViewProcedureActionPerformed

    private void btnAddTransactionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddTransactionActionPerformed
        dispose();
        new AddTransactionWindow().setVisible(true);
    }//GEN-LAST:event_btnAddTransactionActionPerformed

    private void btnEditTransactionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditTransactionActionPerformed
        if(tblTransaction.getSelectedRow() != -1) {
            dispose();
            new EditTransactionWindow(Integer.parseInt(tblTransaction.getValueAt(tblTransaction.getSelectedRow(), 0).toString())).setVisible(true);
        }
        else
            JOptionPane.showMessageDialog(new JFrame(), "Please select a transaction first!", "Error!", JOptionPane.ERROR_MESSAGE);
    }//GEN-LAST:event_btnEditTransactionActionPerformed

private void tblProcedureFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tblProcedureFocusGained
    
   
    
}//GEN-LAST:event_tblProcedureFocusGained

private void btnFilterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFilterActionPerformed
// TODO add your handling code here:
    
    //String sample = "January 1, 2011";
    //Date d= new Date(sample);
    
    //String s = DateFormat.getDateInstance(DateFormat.SHORT).format(d);
    //System.out.println(s);
    
    //System.out.println(jCalendarCombo1.getSelectedDate());
    DateFormat format = new SimpleDateFormat("M d, yyyy");
    DateFormat f = new SimpleDateFormat("M/dd/yyyy");
    
    
    //clear tables//
    for(int i = modelReport.getRowCount(); i > 0; i--) {
            tblReport.setValueAt("", modelReport.getRowCount()-1, 0);
            tblReport.setValueAt("", modelReport.getRowCount()-1, 1);
            tblReport.setValueAt("", modelReport.getRowCount()-1, 2);
            modelReport.removeRow(modelReport.getRowCount()-1);
        }/*
            tblReport.setValueAt("", modelReport.getRowCount()-1, 0);
            tblReport.setValueAt("", modelReport.getRowCount()-1, 1);
            tblReport.setValueAt("", modelReport.getRowCount()-1, 2);
            modelReport.removeRow(modelReport.getRowCount()-1);*/
    
    try{
        ConnectionFactory myFactory = ConnectionFactory.getFactory();
        Connection conn = myFactory.getConnection();
            
        int i = 0;
        
        //gets all dates and makes it into a string
        String date1 = jCalendarCombo1.getSelectedDate();
        Date d1 = f.parse(date1);
        System.out.print(date1 + "  =  ");
        System.out.println(d1);
        
        String date2 = jCalendarCombo2.getSelectedDate();
        Date d2 = (Date)f.parse(date2);
        System.out.print(date2 + "  =  ");
        System.out.println(d2);
        
        PreparedStatement pstmt0 = conn.prepareStatement("SELECT transactionDate FROM transactions GROUP BY transactionDate ORDER BY transactionDate");
        ResultSet rs0 = pstmt0.executeQuery();
        rs0.last();
        int numRows = rs0.getRow();
        String[] Dates = new String[rs0.getRow()];
        String[] Datess = new String[rs0.getRow()];
        rs0.beforeFirst();
        int index = 0;
        while(rs0.next()){
            
            Dates[index] = rs0.getString("transactionDate");
            
            String stuff = rs0.getString("transactionDate");
            Date d = new Date(stuff);
            //System.out.println("lalala "+d);
            //String s = DateFormat.getDateInstance(DateFormat.FULL).format(d);
            String lol = d.toString();
            Date rawr = new Date(lol);
            //String s = f.parse(d);
            System.out.println("lalala "+ lol);
            
            
            //Date rawr = (Date)f.parse(s);
            System.out.println("rawr " + rawr);
            if(rawr.after(d1) && rawr.before(d2)){
                System.out.println("BETWEEEEEEN");
                String tempdatex = DateFormat.getDateInstance(DateFormat.LONG).format(d);
                Datess[index] = tempdatex;
                System.out.println(Datess[index]);
            }
            
            index++;
        }
        
        /*String[] tempDate;
        SimpleDateFormat month = new SimpleDateFormat("M");
        SimpleDateFormat day = new SimpleDateFormat("dd");
        SimpleDateFormat year = new SimpleDateFormat("yyyy");
        for(index = 0; index < numRows - 1; index++){
            
            
            if(rawr.after(d1) && rawr.before(d2)){
                String tempDate = DateFormat.getDateInstance(DateFormat.LONG).format(d);
                tempDate[index] = tempdate;
            }
        }*/
        
        
        String dateString = "";
        for(index = 0; index < numRows-1; index++){
            dateString += "SELECT SUM(procedurePrice) AS ProcSum, COUNT(*) AS ProcNum, dcds.transactions.transactionDate FROM dcds.transprocdetails, dcds.transactions where dcds.transactions.transactiondate = '"+Datess[index]+"' AND dcds.transactions.transactionID = dcds.transprocdetails.transactionID UNION ";
        }
        dateString += "SELECT SUM(procedurePrice) AS ProcSum, COUNT(*) AS ProcNum, dcds.transactions.transactionDate FROM dcds.transprocdetails, dcds.transactions where dcds.transactions.transactiondate = '"+Datess[index]+"' AND dcds.transactions.transactionID = dcds.transprocdetails.transactionID";
        
        PreparedStatement pstmt = conn.prepareStatement(dateString);
        
        ResultSet rs = pstmt.executeQuery();
        
        Total = 0;
        rs.last();
        System.out.println("Last Row: "+ rs.getString("transactionDate") + " " + rs.getInt("procNum") + " " + rs.getDouble("procSum"));
        rs.previous();
        int rows = rs.getRow();
        System.out.println(rows);
        rs.beforeFirst();
        
        if(rows > 0) {
            while(rs.next() && rs.getString("transactionDate") != null){
                String date = rs.getString("transactionDate");

                modelReport.addRow(new Object[] {"", "", ""});
                tblReport.setValueAt(date, i, 0);

                cnt = rs.getInt("procNum");
                pprice = rs.getDouble("procSum");

                tblReport.setValueAt(cnt, i , 1);
                tblReport.setValueAt("Php " + pprice, i, 2);

                Total += pprice;

                String properTotal = ("Php " + Total);

                jTextField3.setText(properTotal);

                i++;
            }
        }
        
        conn.close();
        }catch(Exception e){
        e.printStackTrace();
            }    

}//GEN-LAST:event_btnFilterActionPerformed

private void btnSearchPatientActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchPatientActionPerformed
    try {
        for(int i = modelPatient.getRowCount(); i > 0; i--) {
            tblPatient.setValueAt("", modelPatient.getRowCount()-1, 0);
            tblPatient.setValueAt("", modelPatient.getRowCount()-1, 1);
            tblPatient.setValueAt("", modelPatient.getRowCount()-1, 2);
            tblPatient.setValueAt("", modelPatient.getRowCount()-1, 3);
            tblPatient.setValueAt("", modelPatient.getRowCount()-1, 4);
            modelPatient.removeRow(modelPatient.getRowCount()-1);
        }
        
        ConnectionFactory myFactory = ConnectionFactory.getFactory();
        Connection conn = myFactory.getConnection();
        
        PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM patient WHERE UCASE(CONCAT(pLastName, ', ', pFirstName, ', ', pMiddleName )) LIKE '%"+txtSearchPatient.getText().toUpperCase()+"%'");
        System.out.println("SELECT * FROM patient WHERE UCASE(CONCAT(pLastName, ', ', pFirstName, ', ', pMiddleName )) LIKE '%"+txtSearchPatient.getText().toUpperCase()+"%'");
        ResultSet rs = pstmt.executeQuery();
        rs.last();
        int rowsFetched = rs.getRow();
        System.out.println("Rows Fetched: "+ rowsFetched);
        rs.first();
        
        for(int i = 0; i < rowsFetched; i++) {
            modelPatient.addRow(new Object[] {"","","","",""});
            tblPatient.setValueAt(rs.getInt("patientID"), i, 0);
            tblPatient.setValueAt(rs.getString("pLastName"), i, 1);
            tblPatient.setValueAt(rs.getString("pFirstName"), i, 2);
            tblPatient.setValueAt(rs.getString("pMiddleName"), i, 3);
            tblPatient.setValueAt(rs.getString("pBirthMonth")+" "+rs.getInt("pBirthDay")+", "+rs.getInt("pBirthYear"), i, 4);
            rs.next();
        }
        conn.close();
        
    }catch (Exception e){
        e.printStackTrace();
    }
}//GEN-LAST:event_btnSearchPatientActionPerformed

private void btnSearchTransactionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchTransactionActionPerformed
    try {
        for(int i = modelTransaction.getRowCount(); i > 0; i--) {
            tblTransaction.setValueAt("", modelTransaction.getRowCount()-1, 0);
            tblTransaction.setValueAt("", modelTransaction.getRowCount()-1, 1);
            tblTransaction.setValueAt("", modelTransaction.getRowCount()-1, 2);
            tblTransaction.setValueAt("", modelTransaction.getRowCount()-1, 3);
            modelTransaction.removeRow(modelTransaction.getRowCount()-1);
        }
        
        ConnectionFactory myFactory = ConnectionFactory.getFactory();
        Connection conn = myFactory.getConnection();
        
        PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM transactions WHERE UCASE(pName) LIKE '%"+txtSearchPatientTransaction.getText().toUpperCase()+"%'");
        ResultSet rs = pstmt.executeQuery();
        rs.last();
        int rowsFetched = rs.getRow();
        System.out.println("Rows Fetched: "+ rowsFetched);
        rs.first();
        for(int i = 0; i < rowsFetched; i++) {
            modelTransaction.addRow(new Object[] {"","","",""});
            tblTransaction.setValueAt(rs.getInt("transactionID"), i, 0);
            tblTransaction.setValueAt(rs.getString("transactionDate"), i, 1);
            tblTransaction.setValueAt(rs.getInt("patientID"), i, 2);
            tblTransaction.setValueAt(rs.getString("pName"), i, 3);
            rs.next();
        }
        conn.close();
        
    }catch (Exception e){
        e.printStackTrace();
    }
}//GEN-LAST:event_btnSearchTransactionActionPerformed

private void btnSearchProcedureActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchProcedureActionPerformed
    try {
        for(int i = modelProcedure.getRowCount(); i > 0; i--) {
            tblProcedure.setValueAt("", modelProcedure.getRowCount()-1, 0);
            tblProcedure.setValueAt("", modelProcedure.getRowCount()-1, 1);
            tblProcedure.setValueAt("", modelProcedure.getRowCount()-1, 2);
            modelProcedure.removeRow(modelProcedure.getRowCount()-1);
        }
        
        ConnectionFactory myFactory = ConnectionFactory.getFactory();
        Connection conn = myFactory.getConnection();
        
        PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM procedures WHERE UCASE(procedureName) LIKE '%"+txtSearchProcedure.getText().toUpperCase()+"%'");
        ResultSet rs = pstmt.executeQuery();
        rs.last();
        int rowsFetched = rs.getRow();
        System.out.println("Rows Fetched: "+ rowsFetched);
        rs.first();
        for(int i = 0; i < rowsFetched; i++) {
            modelProcedure.addRow(new Object[] {"","",""});
            tblProcedure.setValueAt(rs.getInt("procedureID"), i, 0);
            tblProcedure.setValueAt(rs.getString("procedureName"), i, 1);
            tblProcedure.setValueAt(rs.getInt("procedurePrice"), i, 2);
            rs.next();
        }
        conn.close();
    }catch (Exception e){
        e.printStackTrace();
    }
}//GEN-LAST:event_btnSearchProcedureActionPerformed

private void txtSearchPatientMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtSearchPatientMouseClicked
    txtSearchPatient.setText("");
}//GEN-LAST:event_txtSearchPatientMouseClicked

private void txtSearchPatientKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtSearchPatientKeyTyped
    if (evt.getKeyChar() == java.awt.event.KeyEvent.VK_ENTER) {
        btnSearchPatient.doClick();
        System.out.println("SEARCH PATIENT: " + txtSearchPatient.getText()); //
        txtSearchPatient.setText("Enter name here...");
    }
}//GEN-LAST:event_txtSearchPatientKeyTyped

private void txtSearchProcedureMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtSearchProcedureMouseClicked
    txtSearchProcedure.setText("");
}//GEN-LAST:event_txtSearchProcedureMouseClicked

private void txtSearchProcedureKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtSearchProcedureKeyTyped
    if (evt.getKeyChar() == java.awt.event.KeyEvent.VK_ENTER) {
        btnSearchProcedure.doClick();
        System.out.println("SEARCH PROCEDURE: " + txtSearchProcedure.getText()); //
        txtSearchProcedure.setText("Enter procedure name here...");
    }
}//GEN-LAST:event_txtSearchProcedureKeyTyped

private void txtSearchPatientTransactionMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtSearchPatientTransactionMouseClicked
    txtSearchPatientTransaction.setText("");
}//GEN-LAST:event_txtSearchPatientTransactionMouseClicked

private void txtSearchPatientTransactionKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtSearchPatientTransactionKeyTyped
    if (evt.getKeyChar() == java.awt.event.KeyEvent.VK_ENTER) {
        btnSearchTransaction.doClick();
        System.out.println("SEARCH TRANSACTION: " + txtSearchPatientTransaction.getText()); //
        txtSearchPatientTransaction.setText("Enter patient's name here...");
    }
}//GEN-LAST:event_txtSearchPatientTransactionKeyTyped

private void txtSearchPatientFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtSearchPatientFocusLost
    if (txtSearchPatient.getText().equals("")) {
        txtSearchPatient.setText("Enter name here...");
    }
}//GEN-LAST:event_txtSearchPatientFocusLost

private void txtSearchPatientFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtSearchPatientFocusGained
    txtSearchPatient.setText("");
}//GEN-LAST:event_txtSearchPatientFocusGained

private void txtSearchProcedureFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtSearchProcedureFocusGained
    txtSearchProcedure.setText("");
}//GEN-LAST:event_txtSearchProcedureFocusGained

private void txtSearchProcedureFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtSearchProcedureFocusLost
    if (txtSearchProcedure.getText().equals("")) {
        txtSearchProcedure.setText("Enter procedure name here...");
    }
}//GEN-LAST:event_txtSearchProcedureFocusLost

private void txtSearchPatientTransactionFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtSearchPatientTransactionFocusGained
    txtSearchPatientTransaction.setText("");
}//GEN-LAST:event_txtSearchPatientTransactionFocusGained

private void txtSearchPatientTransactionFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtSearchPatientTransactionFocusLost
    if (txtSearchPatientTransaction.getText().equals("")) {
        txtSearchPatientTransaction.setText("Enter patient's name here...");
    }
}//GEN-LAST:event_txtSearchPatientTransactionFocusLost

    /**
     * @param args the command line arguments
     */

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAddPatient;
    private javax.swing.JButton btnAddProcedure;
    private javax.swing.JButton btnAddTransaction;
    private javax.swing.JButton btnEditTransaction;
    private javax.swing.JButton btnFilter;
    private javax.swing.JButton btnSearchPatient;
    private javax.swing.JButton btnSearchProcedure;
    private javax.swing.JButton btnSearchTransaction;
    private javax.swing.JButton btnViewPatient;
    private javax.swing.JButton btnViewProcedure;
    private org.gui.JCalendarCombo jCalendarCombo1;
    private org.gui.JCalendarCombo jCalendarCombo2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JLabel labelDate;
    private javax.swing.JLabel labelGreeting1;
    private javax.swing.JPanel panelHome;
    private javax.swing.JPanel panelPatient;
    private javax.swing.JPanel panelProcedure;
    private javax.swing.JPanel panelReport;
    private javax.swing.JPanel panelTransaction;
    private javax.swing.JTabbedPane tabbedPanel;
    private javax.swing.JTable tblPatient;
    private javax.swing.JTable tblProcedure;
    private javax.swing.JTable tblReport;
    private javax.swing.JTable tblTransaction;
    private javax.swing.JTextField txtSearchPatient;
    private javax.swing.JTextField txtSearchPatientTransaction;
    private javax.swing.JTextField txtSearchProcedure;
    // End of variables declaration//GEN-END:variables
   
     
     
 
   
     public int getSelectedPatientID(){
         
          int paRow = tblPatient.getSelectedRow();
          String select = tblPatient.getValueAt(paRow, 0).toString();
          int sel = 0;
          if(paRow!=(-1))
              sel = Integer.parseInt(select);
          System.out.print(select);
          return sel;
          
     }
     
     public int getSelectedProcedureID(){
         
         int paRow = tblProcedure.getSelectedRow();
          String select = tblProcedure.getValueAt(paRow, 0).toString();
          int sel = 0;
          if(paRow!=(-1))
              sel = Integer.parseInt(select);
          System.out.print(select);
          return sel;
     }
     
     
     
     public void setPatientName(String newName){
         
         this.selectPatient = newName;
     }
     
     public void setProcedureName(String newProcedure){
         
         this.selectProcedure = newProcedure;
     }
     
     public List getPatientList(){
         return patientList;
         
     }

     public List getProcedureList(){
         
         return procedureList;
     }
     
     public void addtoPatientList(List newPatient){
         
        this.patientList = newPatient;
     }
     
     class MyClockActionListener implements ActionListener{
                public void actionPerformed(ActionEvent e){
                         labelDate.setText("Today is " +(now("MMMMM dd, yyyy h:mm:ss a")));
                }
        }
        
        public static String now (String dateFormat){
                
                Calendar cal = Calendar.getInstance();
            SimpleDateFormat dateTime = new SimpleDateFormat(dateFormat);
            return dateTime.format(cal.getTime());
        }
     
   
}


